package com.xx.servlet;

import com.xx.dao.JdbcImpl;
import com.xx.dao.JdbcUtils;
import com.xx.dao.Jdbcdao;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@WebServlet("/delUser")
public class DelServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response){
        response.setContentType("text/html;charset=UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        int id = Integer.parseInt(request.getParameter("id"));
        //如果有信息没填写的话,就重新填写
        if(0==(id)){
            try {
                response.sendRedirect("usererror.jsp");
                return;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        Jdbcdao jdbcdao = new JdbcImpl();
        int i = jdbcdao.delUser(id);
        if(i == 1){
            try {
                response.sendRedirect("success.jsp");
                return;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else{
            try {
                response.sendRedirect("fail.jsp");
                return;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response){
        doGet(request,response);
    }
}
